package cn.wolfcode.web.controller;


import cn.wolfcode.domain.ConsumptionItem;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.service.IConsumptionItemService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryItemService;
import cn.wolfcode.util.JsonResult;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/consumptionItem")
public class ConsumptionItemController {

    @Autowired
    private IConsumptionItemService consumptionItemService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequestMapping("/delete")
    @RequiredPermission(name="结算明细单删除",expression="consumptionItem:delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            consumptionItemService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequiredPermission(name="结算明细单新增/编辑",expression="consumptionItem:saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(ConsumptionItem consumptionItem){
        if (consumptionItem.getId() != null) {
            consumptionItemService.update(consumptionItem);
        }else {
            consumptionItemService.save(consumptionItem);
        }
        return new JsonResult();
    }

    //业务大类与业务小类的二级联动
    @RequestMapping("/categoryItemSelect")
    @ResponseBody
    public List<SystemDictionaryItem> categoryItemSelect(Long id){
        return systemDictionaryItemService.selectByParentId(id);
    }
}
